package com.ruoyi.web.controller.website;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.model.UserPhonePo;
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.module.domain.Account;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户信息Controller
 *
 * @author fubojin
 * @date 2024-12-09
 */
@Api(tags = "网页用户登录")
@RestController
@RequestMapping("/website/user")
public class WebUserController extends BaseController {

    @Autowired
    private SysLoginService loginService;

    @Autowired
    private ISysUserService userService;

    @Anonymous
    @ApiOperation("签发临时token-只能使用一次")
    @GetMapping("/temporaryTokenJustOnce")
    public AjaxResult temporaryTokenJustOnce(@RequestParam Long userId) {
        return AjaxResult.success(loginService.temporaryTokenJustOnce(userId));
    }


    @Anonymous
    @ApiOperation("App一键登录")
    @PostMapping("/appLogin")
    public AjaxResult appLogin(@RequestBody UserPhonePo po) {
        return AjaxResult.success().put(Constants.Data, loginService.appLogin(po));
    }


    /**
     * 修改用户信息（客户修改）
     */
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUser user) {
        return toAjax(userService.updateUser(user));
    }
    /**
     * 获取用户信息详细信息
     */
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(userService.selectUserById(userId));
    }


}
